'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
	//event为客户端上传的参数
	const collection = db.collection('bill').where({
		accID: db.command.in([event.id])
	}).get();
	const resData = await db.collection("bill").where({
		accID: db.command.in([event.id])
	}).get();
	const resData2 = await db.collection("bill").limit(5).where({
		accID: db.command.in([event.id])
	}).orderBy('createdTime','desc').get();
	//返回数据给客户端
	let total = 0
	for (let i = 0; i < resData.affectedDocs; i++) {
		total += Number(resData.data[i].money)
	}
	resData2.total = total.toFixed(2)
	console.log(resData.data);
	return {
		code: 200,
		data: resData2
	}
};